package com.guigu.www.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.pojo.*;
import com.guigu.www.service.ManufactureConfigProcedureListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ManufactureConfigProcedureListController {
    @Autowired
    ManufactureConfigProcedureListService mcpService;
    //工序列表

    //查询
    @RequestMapping("querymcplist.action")
    public PageVo<ManufactureConfigProcedureList> querymcplistbypage(ManufactureConfigProcedureList mcplist,
                                                                  @RequestParam(value = "pagenum", defaultValue = "1") int pagenum, @RequestParam(value = "pagesize", defaultValue = "5") int pagesize) {
        //条件查询
        QueryWrapper<ManufactureConfigProcedureList> queryWrapper = new QueryWrapper<ManufactureConfigProcedureList>();

        Page<ManufactureConfigProcedureList> page = mcpService.page(new Page<ManufactureConfigProcedureList>(pagenum, pagesize), queryWrapper);


        PageVo<ManufactureConfigProcedureList> pageVo = new PageVo<ManufactureConfigProcedureList>();
        pageVo.setRows(page.getRecords());
        pageVo.setTotal(page.getTotal());

        return pageVo;
    }

    //根据工序id查询
    @GetMapping("querymcpbyid.action/{id}")
    public ManufactureConfigProcedureList querymcpbyid(@PathVariable int id)
    {
        return mcpService.getById(id);
    }

    //添加
    @RequestMapping("addmcppojo.action")
    public Map addmcppojo(@RequestBody ManufactureConfigProcedureList designProcedure
    ) {
        Map map = new HashMap();
        boolean f = mcpService.save(designProcedure);
        if (f) {
            map.put("msg", "添加成功");
        } else {
            map.put("msg", "添加失败");
        }
        return map;
    }

    //修改
    @RequestMapping("updatemcppojo.action")
    public Map updatemcppojo(@RequestBody ManufactureConfigProcedureList designProcedure
    ) {
        Map map = new HashMap();
        boolean f = mcpService.updateById(designProcedure);
        if (f) {
            map.put("msg", "修改成功");
        } else {
            map.put("msg", "修改失败");
        }

        return map;
    }

    //删除
    @RequestMapping("delmcppojo.action/{applyid}")
    public Map delmcppojo(@RequestBody Integer applyid
    ) {
        Map map = new HashMap();
        boolean f = mcpService.removeById(applyid);
        if (f) {
            map.put("msg", "删除成功");
        } else {
            map.put("msg", "删除失败");
        }

        return map;
    }

}
